package cn.yangliu.nacos.comm.config;

import cn.yangliu.nacos.comm.oauth.Oauth2FeignIntercepter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.FeignClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * The type of nacos.
 *
 * @author 问道于盲
 * @date 2019 -12-31
 */
@Configuration
@EnableConfigurationProperties(Oauth2Properties.class)
@ConditionalOnClass(FeignClientBuilder.class)
public class Oauth2Config {

    /**
     * current class instance's member.
     * The Properties.
     */
    @Autowired
    private Oauth2Properties properties;

    /**
     * Oauth 2 feign intercepter oauth 2 feign intercepter.
     *
     * @return the oauth 2 feign intercepter
     */
    @Bean
    public Oauth2FeignIntercepter oauth2FeignIntercepter() {
        return new Oauth2FeignIntercepter(properties.getClientId(),
                properties.getClientSecret());
    }

}
